#pragma once
#include <QComboBox>
#include <QListWidget>

#include "widgets.h"

class QCheckBox;
class S_WIDGETS_EXPORT SCheckComboBox : public QComboBox {
  Q_OBJECT
 public:
  SCheckComboBox(QWidget* parent = nullptr, bool hasCheckAll = false,
                 const QString& checkAllText = "");
  void addItem(const QString& text, const QVariant& userData = QVariant());
  QStringList currentText() const;
  int count() const;
  void SetPlaceHolderText(const QString& placeHolderText);
  void ResetSelection();
  void setCheck(int index,
                bool checked);  // 修改状态时，可能信号selectionChanged不触发
  void setSelectStated(int index, bool selected);  // 反复修改状态时，用这个？
  bool getCheck(int index) const;
  QString getDataText(int index);
 signals:
  void selectionChanged();

 protected:
  void hidePopup() override;
  bool eventFilter(QObject* object, QEvent* event) override;

 private:
  QString styleSheet() const;
  QCheckBox* getCheckBox(int index) const;
  void onCheckBoxClicked(bool checked);
  void stateChanged(int state);
  void itemClicked(int index);
  void clickCheckBox(QCheckBox* cb, bool checked);

 private:
  QCheckBox* m_checkBoxAll;
  QLineEdit* m_lineEdit;
  QListWidget* m_listWidget;
  bool m_hasCheckAll;
  std::vector<QString> m_comboxData;
};